﻿using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace WhaleAccount.Models;
public class YearRecordSummary : INotifyPropertyChanged
{
    private double income;
    private double expense;
    private double balance;
    public double Income
    {
        get => income;
        set
        {
            var round = Math.Round(value, 2);
            if (income != round)
            {
                income = round;
                OnPropertyChanged();
            }
        }
    }
    public double Expense
    {
        get => expense;
        set
        {
            var round = Math.Round(value, 2);
            if (expense != round)
            {
                expense = round;
                OnPropertyChanged();
            }
        }
    }
    public double Balance
    {
        get => balance;
        set
        {
            var round = Math.Round(value, 2);
            if (balance != round)
            {
                balance = round;
                OnPropertyChanged();
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    public void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        // Raise the PropertyChanged event, passing the name of the property whose value has changed.
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
